package com.prs.crm.dao.cdxh.impl;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import com.prs.crm.dao.cdxh.MachineClassDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cdxh.production.MachineClass;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-3 上午09:59:33
 * 简单说明
 */

public class MachineClassDaoImpl extends BaseDaoImpl<MachineClass> implements
		MachineClassDao {
	/**
	 * 查询某生产类型中的最大ID值。
	 * @param productType
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public MachineClass serchMaxIdObject(final String productType) {
		return (MachineClass)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(MachineClass.class);
				        	criteria.add(Restrictions.eq("productType", productType));
				        	List<MachineClass> result = criteria.list();
				        	int judge=0;
				        	for(int i=0;i<result.size();i++){
				        		int zid=result.get(i).getId();
				        		if(zid>judge){
				        			judge=i;
				        		}
				        	}
				        	
				        	return result.get(judge);
				        }   
				 } );
	}

}
